package com.gitee.kenewstar.migration.api;

import com.alibaba.excel.EasyExcel;
import com.gitee.kenewstar.migration.entity.CommonResult;
import com.gitee.kenewstar.migration.entity.JobInfo;
import com.gitee.kenewstar.migration.entity.Lov;
import com.gitee.kenewstar.migration.service.migration.JobMigrationService;
import com.gitee.kenewstar.migration.util.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
 * @author kenewstar
 */
@RestController
@RequestMapping("/job")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class JobApi {

    private final JobMigrationService jobMigrationService;


    @PostMapping("/job-migration")
    public List<CommonResult> jobMigration(@RequestBody List<String> jobCodeList,
                                           @RequestParam(required = false) Long tenantId) {
        return this.jobMigrationService.jobInfoMigration(jobCodeList, tenantId);
    }

    @PostMapping("/excel-job-migration")
    public List<CommonResult> excelJobMigration(@RequestPart("file") MultipartFile file) {
        return this.jobMigrationService.jobInfoMigration(ExcelUtil.filterReadData(file, JobInfo.class));
    }


}
